package leetcode;

public class Day10 {
    public static  int numDecodings(String s) {
        int n=s.length();
        int[] dp=new int[n];
        char[] arr=s.toCharArray();
        if(arr[0]!='0'){
            dp[0]=1;
        }
        if(arr[1]!='0'&&arr[0]!='0'){
            dp[1]+=1;
        }
        int t=(arr[0]-'0')*10+arr[1]-'0';
        if (t>=10&&t<=26){
            dp[1]+=1;
        }
        for (int i=2;i<n;i++ ){
            if(arr[i]!='0'){
                dp[i]+=dp[i-1];
            }
            int tt=(arr[i-1]-'0')*10+arr[i]-'0';
            if (tt>=10&&tt<=26){
                dp[i]+=dp[i-2];
            }
        }
        return dp[n-1];
    }

    public static void main(String[] args) {
        int x=numDecodings("2101");
        System.out.println(x);
    }
}
